﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebSimplicity.Data;
using WebSimplicity.Data.Helpers;

namespace WebSimplicity.Admin.Controllers
{
    public class PagesController : Controller
    {
        static Website web = new Website().Current();
        //
        // GET: /Pages/

        public ActionResult Index()
        {
            Entities db = new Entities(Config.GetConnection("Data.Model"));
            var pages = db.ContentPages.Where(i => i.WebsiteId == web.WebsiteId); 
            return View(pages);
        }


        public ActionResult Create()
        {
            return View();
        }
        [HttpPost]
        public ActionResult Create(ContentPage page)
        {
            page.Create();
            return RedirectToAction("index", "pages");

        }
        public ActionResult Edit(int id)
        {
            Entities db = new Entities(Config.GetConnection("Data.Model"));
            var page = db.ContentPages.Single(i => i.WebsiteId == web.WebsiteId && i.PageId == id); 
            return View(page);
        }

        [HttpPost]
        public ActionResult Edit(int id, ContentPage page)
        {

            page.Update(id);
            return RedirectToAction("index", "pages");
        }
    }
}
